<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta http-equiv="X-UA-Com  patible" content="ie=edge">
    <link rel="stylesheet" href="__CSS__/ex/common.css">
    <link rel="stylesheet" href="__CSS__/ex/login.css">
    <title>闪兑</title>
    <script src="__JS__/ios-web-app.js"></script>
</head>

<body style="padding-top: 38px">
    <header class="normal_header">
        <div class="header_pic">
            <a href="{:U('Index/index')}"><img src="__IMG__/ex/back_black.png" alt="" width=></a>
        </div>
        <p style="padding-left:.2rem;color: #000">Flash cash</p>
        <div style="float: right;">
            <a href="{:U('duihuan/history')}" style="color: #000;font-size: .34rem">Record</a>
        </div>
    </header>
    <section class="change_content">
<!--        <div>-->
<!--            <if condition="$config.ptr44 eq 1">-->
<!--                第{$config.ptr39}轮限量抢购{$config.ptr25}EXUU，目前剩余{$config.ptr26}枚-->
<!--            </if>-->

<!--        </div>-->
        <div class="shandui">
            <div class="pay">
<!--                <div class="from">-->
<!--                    <span index="8">USDT</span>-->
<!--                </div>-->
                <h3>Payment</h3>
                <div  style="display: flex;align-items: center;justify-content: space-between">

                <div class="axz">
                    <input type="text" placeholder="Default quantity is 1" id="from_num" value="">
<!--                    <span>枚</span>-->
                </div>
                    <div style="display: flex;align-items: center;">
                        <div class="img_box">
                        <img src="__IMG__/ex/zn_40.png" id="sweet" alt="" style="display: inline">
                        <img src="__IMG__/ex/exlogo1.png" id="dacm" alt="" >
                        <img src="__IMG__/ex/USDT.png" id="usdt" alt="">
                        </div>
                        <select id="from" v-model="selected">
                            <option value="1">SWEET</option>
                            <option value="2">DACM</option>
                            <option value="8">USDT</option>
                        </select>
                    </div>
                </div>
                <p>
                    <span>available</span>
                    <span style="float: right;" class="shandui_btn all">All</span>
                    <span style="float: right;padding: .1rem 0;color:#EC1C24;"><span id="balance">{$UserInfo.z1}</span>&nbsp;<span id="coinname">SWEET</span></span>

                </p>
                <p class="exchange_price" style="text-align: right;line-height: .4rem;font-size: .26rem">Exchange rate：<span>1</span><span class="from_logo">USDT</span>&nbsp;≈&nbsp;<span class="jiage">1</span><span class="to_logo">SWEET</span></p>
            </div>
            <div>
                <img src="__IMG__/ex/Tr.png" alt="" class="qiehuan">
            </div>
            <div class="transfer">
<!--                <div class="to">-->
<!--                    <span index="1">EXUU</span>-->
<!--                </div>-->
                <h3>Exchange</h3>
                <div></div>
                <div  style="display: flex;align-items: center;justify-content: space-between">
                    <div class="axz">
                        <input type="text" id="shandui_num" value="" readonly>
                        <!--                    <span>枚</span>-->
                    </div>
                    <div style="display: flex;align-items: center">
                        <div class="img_box2">
                            <img src="__IMG__/ex/USDT.png" id="usdt2" alt="" style="display: inline">
                            <img src="__IMG__/ex/exlogo1.png" id="dacm2" alt="" >
                            <img src="__IMG__/ex/zn_40.png" id="sweet2" alt=""  >
                        </div>
                        <select id="to" v-model="selected">
                            <option value="8" selected>USDT</option>
                            <!--<option value="2">DACM</option>-->
                        </select>
                    </div>

                </div>

                <p style="color: #A9A9A9;">

                    <div style="display: flex;align-items: center;justify-content: space-between;color: #A9A9A9;font-size: .26rem">
                             <span>
                             Service Charge:5%
                            </span>
                        <div >
                            <span  style="display: flex;align-items: center;">Miner's fee:<span>{$config.a51}</span> DACM</span>
                        </div>

                     </div>
                </p>
                <div>
                    <img src="__IMG__/tt.png"  style="margin: 0;width: .2rem;display: inline;"/><span style="color: #EC1C24;font-size: 10px;">&nbsp;Make sure the currency information is correct before flash cash! Once converted, it cannot be withdrawn!</span>
                </div>

            </div>


        </div>
        <button class="sure">Quick flash cash</button>

<!--        <p class="fee">手续费：<span style="color: red">0%</span></p>-->
<!--        <ul class="mrecord">-->
<!--            <li>-->
<!--                <span>全部</span>-->
<!--                <span>数量</span>-->
<!--                <span>状态</span>-->
<!--            </li>-->
<!--            <volist name="exchange_list" id="vo">-->
<!--                <li>-->
<!--                    <span>-->
<!--                        <if condition="$vo.from_coin eq 1">-->
<!--                            EXUU/USDT-->
<!--                            <else />-->
<!--                            USDT/EXUU-->
<!--                        </if>-->
<!--                    </span>-->
<!--                    <span>{$vo.from_coin_num}/{$vo.to_exchange_num}</span>-->
<!--                    <div>-->
<!--                        <if condition="$vo.status eq 0">-->
<!--                            <span class="status">待审</span>-->
<!--                            <elseif condition="$vo.status eq 2"/>-->
<!--                            <span class="tongguo">通过</span>-->
<!--                            <else />-->
<!--                            <span class="bohui">驳回</span>-->
<!--                        </if>-->

<!--                    </div>-->
<!--                    </li>-->
<!--            </volist>-->
<!--        </ul>-->
    </section>
<!--    sweet兑换dacm-->
    <input type="hidden" id="p1" value="{$config.p1}">
<!--    usdt兑换sweet-->
    <input type="hidden" id="p2" value="{$config.p2}">
<!--    dacm兑换usdt-->
    <input type="hidden" id="p3" value="{$config.p3}">
    <input type="hidden" id="p4" value="{$config.p4}">
    <input type="hidden" id="p5" value="{$config.p5}">
    <input type="hidden" id="p6" value="{$config.p6}">
    <input type="hidden" id="fee1" value="{$config.fee1}">
    <input type="hidden" id="fee2" value="{$config.fee2}">
    <input type="hidden" id="fee3" value="{$config.fee3}">
    <input type="hidden" id="fee4" value="{$config.fee4}">
    <input type="hidden" id="fee5" value="{$config.fee5}">
    <input type="hidden" id="fee6" value="{$config.fee6}">
    <input type="hidden" id="z1" value="{$UserInfo.z1}">
    <input type="hidden" id="z2" value="{$UserInfo.z2}">
    <input type="hidden" id="z8" value="{$UserInfo.z8}">
    <input type="hidden" id="exchange_least" value="{$config.exchange_least}">
    <style>
        .normal_header{
            display: block;
        }
        .normal_header div, .normal_header p, .normal_header a{
            display: inline-block;
            color: #fff
        }
        .mrecord{
            margin-top: .4rem;
        }
        .mrecord li {
            padding: 0 .2rem;
            box-sizing: border-box;
        }
        .mrecord li span:first-child{
            width: 3rem;
        }
        .mrecord li span.status{
            display: inline-block;
            width: 1.5rem;
            text-align: center;
            line-height: .6rem;
            background-color: #06b57a;
            color: #fff;
            border-radius: .08rem;
        }

        .mrecord li span.tongguo{
            display: inline-block;
            width: 1.5rem;
            text-align: center;
            line-height: .6rem;
            background-color: deepskyblue;
            color: #fff;
            border-radius: .08rem;
        }
        .mrecord li span.bohui{
            display: inline-block;
            width: 1.5rem;
            text-align: center;
            line-height: .6rem;
            background-color: red;
            color: #fff;
            border-radius: .08rem;
        }
        .from ,.to{
            line-height: .6rem;
            background-color: #fff;
            padding-left: .2rem;
            margin-bottom: .2rem;
        }
        .sure{
            width: 6.32rem;
            margin: .4rem auto 0;
            line-height: .88rem;
            border-radius: 25px;
            text-align: center;
            color: #fff;
            background-color:#EC1C24;
            display: block;
        }
        .axz{
            position: relative;
            display: inline-block;
        }
        .axz span{
            position: absolute;
            top: 0;
            /*right: .2rem;*/
            display: inline-block;
            line-height: .6rem;
        }
        .jiage,.fee{
            text-align: center;
            margin-top: .3rem;
            line-height: .4rem;
        }

        .shandui{
            display: block;
        }
        .shandui > div{
            margin: 0 auto;
            margin-top: .3rem;
        }
        .shandui h3{
            padding-bottom: .2rem;
            margin-bottom: .2rem;
            border-bottom: 1px solid #F1F3F4;
        }
        .shandui p{
            padding-top: .2rem;
            margin-top: .2rem;
            border-top: 1px solid #F1F3F4;
        }
        .pay,.transfer{
            background: #fff;
            width: 90% !important;
            padding: .3rem .2rem;
            -webkit-border-radius: 6px;
            -moz-border-radius: 6px;
            border-radius: 6px;
        }
        .shandui select{
            margin: 0;
            -webkit-appearance: none;
            background: url(/Public/Home/images/ex/down.png) no-repeat scroll right center transparent;
            /*background-size: 20% 70%;*/
            background-size: 23% 60%;
        }
        #from,#to{
            /*width: 1.7rem;*/
            width: 1.3rem;
            margin-left: .1rem;
        }
        .shandui_btn{
            background:#EC1C24;
            color: #fff;
            border-radius:25px;
            padding:.05rem .25rem;
            margin-left: .3rem;
        }
        .transfer p{
            margin: .1rem 0;
            line-height: .4rem;
        }
    </style>
    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script>
        var exchange_least = $("#exchange_least").val()
        $(document).on('click','.sure',function () {
            var dui = $(this)
            // alert($("#to").val());
            // return
            if($("#from_num").val()==''){
                alert('Please input quantity');return false;
            }
            if(isNaN($("#from_num").val())){
                alert('Illegal number');return false;
            }
            if ($("#from").val() == '1'){
                //sweet 兑换 30个起
                if (parseFloat($("#from_num").val()) < parseFloat(exchange_least)){
                    alert(exchange_least+'SWEET Starting cash');return false;
                }
            }
            if(confirm('Please check whether the exchange quantity is correct')){
                dui.attr('disabled',true).css('pointer-events','none')
                $.ajax({
                    type:"post",
                    dataType: "json",
                    url:"{:U('index')}",
                    data:{
                        from_coin:$("#from").val(),
                        from:$("#from_num").val(),
                        to_coin:$("#to").val(),
                        to:$("#shandui_num").val(),
                    },
                    success:function (data) {
                        if(data.code==-1){
                            alert(data.message);
                            window.location.href="{:U('Finance/live')}";
                        }else if(data.code>0){
                            alert(data.message);
                            window.location.reload();
                        }else {
                            alert(data.message);
                            dui.attr('disabled',false).css('pointer-events','auto')
                        }
                    }

                })
            }

        })
        
        $('.qiehuan').click(function () {
            return false;
            // $left=$(".from").text();
            // $right=$('.to').text();
            // $('.from').text($right);
            // $('.to').text($left);
            $left=$(".from").html();
            $right=$(".to").html();
            $('.from').html($right);
            $('.to').html($left);
            // return false;
            getusdt();
        })

        $('#from').on('change',function () {
            var type = $(this).val()
            if (type == 1){
                //sweet兑换
                // var str = '<option value="8" selected>USDT</option>\n' +
                //     '<option value="2">DACM</option>';
                var str = '<option value="8" selected>USDT</option>';
                var balance = $("#z1").val()
                var coin = 'SWEET';
            } else if (type == 2) {
                var str = '<option value="1" selected>SWEET</option>' +
                    '<option value="8">USDT</option>';
                var balance = $("#z2").val()
                var coin = 'DACM';
            }else if (type == 8){
                var str = '<option value="1" selected>SWEET</option>' +
                    '<option value="2">DACM</option>';
                var balance = $("#z8").val()
                var coin = 'USDT';
            }
            $("#to").html(str)
            $("#balance").text(balance)
            $("#coinname").text(coin)
            $("#from_num").val('')
            $(".from_logo").text(coin)
            getusdt()
            change_icon()
        })
        $(".all").click(function () {
            $("#from_num").val($("#balance").text())
            getusdt()
        })
        $("#to").on('change',function () {
            getusdt()
            change_icon()
        })

        $("#from_num").bind('input propertychange',function () {
            getusdt()
        })

        getusdt();
        function getusdt() {
            let value = $("#from_num").val()
            let reg =/[^\d]/g
            if (value.match(reg)) {
                value = value.replace(/[^\d.]/g,'')
                $("#from_num").val(value)
            }

            if($("#from_num").val()==''){
                var num=1;
            }else {
                var num=$("#from_num").val();
            }
            var from = $("#from").val()
            var to = $("#to").val()
            if (from==1){
                //sweet
                var from_logo = 'SWEET';
                if (to==8){
                    //sweet兑换usdt
                    var price = parseFloat($("#p3").val())
                    var fee = parseFloat($("#fee3").val())
                    var to_num = (num*price).toFixed(4)
                    var to_logo = 'USDT';
                }else {
                    //sweet兑换dacm
                    var price = parseFloat($("#p1").val())
                    var fee = parseFloat($("#fee1").val())
                    var to_num = (num*price).toFixed(4)
                    var to_logo = 'DACM';
                }
            }else if (from == 2) {
                //dacm
                var from_logo = 'DACM';
                if (to==8){
                    //dacm兑换usdt
                    var price = parseFloat($("#p5").val())
                    var fee = parseFloat($("#fee5").val())
                    var to_num = (num*price).toFixed(4)
                    var to_logo = 'USDT';
                }else {
                    //dacm兑换 sweet
                    var price = parseFloat($("#p2").val())
                    var fee = parseFloat($("#fee2").val())
                    var to_num = (num*price).toFixed(4)
                    var to_logo = 'SWEET';
                }
            }else if (from == 8){
                //usdt
                var from_logo = 'USDT';
                if (to==1){
                    //usdt兑换sweet
                    var price = parseFloat($("#p4").val())
                    var fee = parseFloat($("#fee4").val())
                    var to_num = (num*price).toFixed(4)
                    var to_logo = 'SWEET';
                }else {
                    //usdt兑换 dacm
                    var price = parseFloat($("#p6").val())
                    var fee = parseFloat($("#fee6").val())
                    var to_num = (num*price).toFixed(4)
                    var to_logo = 'DACM';
                }
            }
            to_num = (num*(1-fee/100)*price).toFixed(4)
            $("#shandui_num").val(to_num)
            // $(".jiage>span").text(price)
            $(".jiage").text(price)
            $(".fee").text(fee)
            $(".from_logo").text(from_logo)
            $(".to_logo").text(to_logo)

            // if($(".to>span").attr('index')==8){
            //     // $shandui=($num*$exuuapi/res.rate).toFixed(2);
            //     $shandui=($num*$exuuapi).toFixed(2);
            //     $("#shandui_num").val($shandui);
            // }
            // if($(".to>span").attr('index')==1){
            //     // $shandui=($num*res.rate/$exuuapi).toFixed(2);
            //     $shandui=($num/$exuuapi).toFixed(2);
            //     $("#shandui_num").val($shandui);
            // }
            
            // $.ajax({
            //     type: "post",
            //     url: "{:U('Hangqing/api')}",
            //     data: {},
            //     dataType: "json",
            //     success: function (res) {
            //         // console.log(res.change);
            //         //console.log(res.price);
            //         if (res) {
            //             if($("#from_num").val()==''){
            //                 $num=1;
            //             }else {
            //                 $num=$("#from_num").val();
            //             }
            //             if($(".to>span").attr('index')==8){
            //                 // $shandui=($num*$exuuapi/res.rate).toFixed(2);
            //                 $shandui=($num*$exuuapi).toFixed(2);
            //                 $("#shandui_num").val($shandui);
            //             }
            //             if($(".to>span").attr('index')==1){
            //                 // $shandui=($num*res.rate/$exuuapi).toFixed(2);
            //                 $shandui=($num/$exuuapi).toFixed(2);
            //                 $("#shandui_num").val($shandui);
            //             }
            //
            //             // $('#iii').text(parseFloat(res.rate).toFixed(4));
            //
            //
            //             // $('#iii').parent().find('button').text(res.change + '%');
            //             // if (res.change < 0) {
            //             //     $("#iii").parent().find('button').addClass('reduce');
            //             // } else {
            //             //     $("#iii").parent().find('button').addClass('add');
            //             //     $('#iii').parent().find('button').text('+' + res.change + '%');
            //             // }
            //         } else {
            //             alert(res.msg);
            //         }
            //     }
            // });
        }

        function change_icon() {
            var from = $("#from").val();
            var to = $("#to").val()
            $(".img_box img").hide()
            if (from==1){
                $("#sweet").show()
            }else  if (from==2){
                $("#dacm").show()
            } else if (from==8){
                $("#usdt").show()
            }

            $(".img_box2 img").hide()
            if (to==1){
                console.log(1)
                $("#sweet2").show()
            }else  if (to==2){
                console.log(2)
                $("#dacm2").show()
            } else if (to==8){
                console.log(3)
                $("#usdt2").show()
            }
        }

        function role(){
            var sel1 = document.getElementById('from');
            var index = sel1.selectedIndex;
            var value=sel1.options[index].value;
            console.log(value);
            if(value==1){
                $('.img_box img').css('display','none');
                $('#sweet').css('display','inline');
                $('#USD').css('display','inline')
            }else if(value==2){
                $('.img_box img').css('display','none');
                $('#dacm').css('display','inline');
                $('#USD').css('display','inline')
            }else {
                $('.img_box img').css('display','none');
                $('#usdt').css('display','inline');
                $('#USD').css('display','inline')
            }
            // var price = $("#selectid option:selected").attr('price')
            // console.log(price)
            // $("#price").text(price)
            // $("#after").text('0.00')
            // $("#from_num").val('')
        }
        function roled(){
            var sel1 = document.getElementById('to');
            var index = sel1.selectedIndex;
            var value=sel1.options[index].value;
            console.log(value);
            if(value==8){
                $('.img_box2 img').css('display','none');
                $('#usdt2').css('display','inline');
                $('#USD').css('display','inline')
            }else {
                $('.img_box2 img').css('display','none');
                $('#dacm2').css('display','inline');
                $('#USD').css('display','inline')
            }
            // var price = $("#selectid option:selected").attr('price')
            // console.log(price)
            // $("#price").text(price)
            // $("#after").text('0.00')
            // $("#from_num").val('')
        }
    </script>
</body>

</html>